package com.medication.model;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.beust.jcommander.internal.Lists;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

/**
 * 三大类限制
 * 
 * @author heem
 * @create time 创建时间：2017年3月29日 下午4:26:35
 * @version 1.0
 * @since
 */
@SuppressWarnings("serial")
public class ThreeMedicationDir extends Model<ThreeMedicationDir> implements com.medication.utils.ExcelExporter.Cellable {

	public static ThreeMedicationDir dao = new ThreeMedicationDir();

	public Page<ThreeMedicationDir> query(int pageNumber, String code, String name) {
		String select = "select t.* ,t1.id as limitId,t1.code as limitCode,t1.name as limitName,t1.type as limitType,"
				+ " t1.reagentType as limitReagentType ,t1.limit as limitLimit,t1.remark as limitRemark ";
		StringBuilder from = new StringBuilder(
				" from three_medication_dir t full join limit_medication t1 on t.code =t1.code where 1=1 ");
		List<Object> params = Lists.newArrayList();
		if (!StringUtils.isEmpty(code)) {
			from.append(" and ( t.code like ? or t1.code like ? )");
			params.add("%" + code + "%");
			params.add("%" + code + "%");
		}
		if (!StringUtils.isEmpty(name)) {
			name = name.toUpperCase();
			from.append(" and (t.name like ? or t1.name like ? or t.nameFirstEn like ? or t.nameAllEn like ? or t1.nameFirstEn like ? or t1.nameAllEn like ? )");
			params.add("%" + name + "%");
			params.add("%" + name + "%");
			params.add("%" + name + "%");
			params.add("%" + name + "%");
			params.add("%" + name + "%");
			params.add("%" + name + "%");
		}
		//from.append(" order by t.code,t1.code");
		return dao.paginate(pageNumber, 20, select, from.toString(), params.toArray());
	}

	@Override
	public String[] getCellValues() {
		List<String > values = Lists.newArrayList();
		values.add(getStr("code"));
		values.add(getStr("name"));
		values.add(getStr("type"));
		values.add(getStr("payedGrade"));
		values.add(getStr("price"));
		values.add(getStr("unit"));
		values.add(getStr("standard"));
		values.add(getStr("reagentType"));
		values.add(getStr("selfPercent"));
		values.add(getStr("limitPrice"));
		values.add(getStr("heightLimitPrice"));
		values.add(getStr("provinceLimitPrice"));
		values.add(getStr("cityLimitPrice"));
		values.add(getStr("countyLimitPrice"));
		values.add(getStr("villageLimitPrice"));
		values.add(getStr("bedPrice"));
		values.add(getStr("remark"));
		return values.toArray(new String[]{});
	}

}
